package com.store.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.store.comstant.BasePageForm;

public class PageHelperUtil {

    static ThreadLocal<BasePageForm> threadLocalPageForm = new ThreadLocal<BasePageForm>();

    static ThreadLocal<IPage> threadLocalPage = new ThreadLocal<IPage>();

    public static void setThreadLocalPage(BasePageForm basePageForm){
        threadLocalPageForm.set(basePageForm);
    }

    public static void removeThreadLocalPage(BasePageForm basePageForm){
        threadLocalPageForm.remove();
    }

    public static IPage getThreadLocalPage(){
        IPage page  = PageHelperUtil.getMPlusPageByBasePage(threadLocalPageForm.get());
        return page;
    }





    public static IPage getMPlusPageByBasePage(BasePageForm basePageForm){
        Page page = new Page(basePageForm.getCurrentPage(),basePageForm.getPageSize());
        page.setOrders(basePageForm.getOrders());
        return page;
    }




}
